{template '_header'}
 
<div class="page-heading"> 
	
	<span class='pull-right'>
        <a class="btn btn-primary btn-sm" href="{php echo webUrl('system/plugin/perm/add')}">添加新权限</a>
		<a class="btn btn-default  btn-sm" href="{php echo webUrl('system/plugin/perm')}">返回列表</a>
                
                
	</span>
	<h2><i class="fa fa-circle-o"></i>{if !empty($account)}编辑{else}添加{/if}公众号权限 <small>{if !empty($account)}修改【{$account['name']}】权限{/if}</small></h2> 
</div>
 
    <form id="dataform" action="" method="post" class="form-horizontal form-validate" >
        <input type="hidden" name="id" value="{$item['id']}" />
 
                 
					 
                 <div class="form-group type-wechat">
                    <label class="col-sm-2 control-label"><span style='color:red'>*</span>  选择公众号</label>
                    <div class="col-sm-9 col-xs-12">
                        
                  <?php echo tpl_selector('acid',array(
                'preview'=>false, 
                 'text'=>'name',
                 'key'=>'acid',
                'url'=>webUrl('system/plugin/perm/query'),
                'items'=>$account,
                'placeholder'=>'公众号名称',
                'buttontext'=>"选择公众号"))
                ?>
                
                    </div>   
                </div>
          <div class="form-group form-coms">
                    <label class="col-sm-2 control-label">开放组件</label>
                    <div class="col-sm-9 col-xs-12">
                         <label class='checkbox-inline'>
                             <input type='checkbox' name='coms[]' class='com-all' value=''/> 全选
                         </label>
                        <br/>
                        
                         {loop $coms $com}
                         <label class='checkbox-inline' style='margin:0;margin-right:5px;'>
                             <input type='checkbox' name='coms[]' class='com-item' value='{$com['identity']}' {if in_array($com['identity'],$item_coms)} checked{/if} /> {$com['name']}
                         </label>
                        {/loop}
                    </div>
                </div> 
        
                 <div class="form-group form-plugins">
                    <label class="col-sm-2 control-label">开放插件</label>
                    <div class="col-sm-9 col-xs-12">
                         <label class='checkbox-inline'>
                             <input type='checkbox' name='plugins[]' class='plugin-all' value=''/> 全选
                         </label>
                        <br/>
                        
                         {loop $plugins $plugin}
                         <label class='checkbox-inline' style='margin:0;margin-right:5px;'>
                             <input type='checkbox' name='plugins[]' class='plugin-item' value='{$plugin['identity']}' {if in_array($plugin['identity'],$item_plugins)} checked{/if} /> {$plugin['name']}
                         </label>
                        {/loop}
                    </div>
                </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">允许增加多商户数量</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input type="text" name="datas[max_merch]" class="form-control" value="{$datas['max_merch']}">
                    <span class="input-group-addon">个</span>
                </div>
                <span class="help-block">默认为空或者默认0都为不限制</span>
            </div>
        </div>


                <div class="form-group"></div>
                  <div class="form-group">
                   <label class="col-sm-2 control-label"></label>
                   <div class="col-sm-9 col-xs-12">
                       <input type="submit"  value="提交" class="btn btn-primary" />
                       
                       <input type="button" name="back" onclick='history.back()' style='margin-left:10px;' value="返回列表" class="btn btn-default" />
                   </div>
                  </div>
    </form>
 
<script language='javascript'>
    function checkAll(obj){
          var allcheck = true;
           $('.plugin-item').each(function(){
                if(!$(this).get(0).checked){
                     allcheck =false;
                     return false;
                }
            });
            $(".plugin-all").get(0).checked = allcheck;
    }
        function checkAllCom(obj){
          var allcheck = true;
           $('.com-item').each(function(){
                if(!$(this).get(0).checked){
                     allcheck =false;
                     return false;
                }
            });
            $(".com-all").get(0).checked = allcheck;
    }
 $(function(){
     $('.plugin-item').click(function(){
          checkAll();
     });
     $('.com-item').click(function(){
          checkAllCom();
     });
     $('.plugin-all').click(function(){
         var check = $(this).get(0).checked;
        $('.plugin-item').each(function(){
            $(this).get(0).checked = check;
         });
     })
     
     $('.com-all').click(function(){
         var check = $(this).get(0).checked;
        $('.com-item').each(function(){
            $(this).get(0).checked = check;
         });
     })
     
     $(":radio[name=type]").click(function(){
         if($(this).val()=='0'){
             $('.type-wechat').hide();
             $('.type-user').show();
         }
         else{
              $('.type-wechat').show();
             $('.type-user').hide();
         }
     })
 })
   $('form').submit(function(){
       var type =$(":radio[name=type]:checked").val();
       if(type=='0'){
        if ($(':input[name=user]').isEmpty()) {
             Tip.focus($(':input[name=user]'), '请选择用户!');
             return false;
        }
    }else{
        if ($(':input[name=account]').isEmpty()) {
             Tip.focus($(':input[name=account]'), '请选择公众号!');
             return  false;
        }
    }
        return true;
       
   })
  
</script>
{template '_footer'}